﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.ChangeTracking;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EcoSystem.EntityFrameworkCore
{
    public static class BuilderExtensions
    {

        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="TProperty"></typeparam>
        /// <param name="builder"></param>
        /// <returns></returns>
        public static PropertyBuilder<TProperty> HasObjectConversion<TProperty>(
            this PropertyBuilder<TProperty> builder) where TProperty : new()
        {
            builder.HasConversion(new ObjectValueConverter<TProperty>())
                  .Metadata.SetValueComparer(new ValueComparer<TProperty>(true));
            return builder;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="TProperty"></typeparam>
        /// <param name="builder"></param>
        /// <returns></returns>
        public static PropertyBuilder<TProperty> HasEncryptionConversion<TProperty>(
            this PropertyBuilder<TProperty> builder) where TProperty : new()
        {
            builder.HasConversion(new EncryptionConverter<TProperty>())
                  .Metadata.SetValueComparer(new ValueComparer<TProperty>(true));
            return builder;
        }

    }
}
